package com.ywb.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ywb.entity.EduTeacher;
import com.ywb.entity.vo.TeacherConditionVo;
import com.ywb.mapper.EduTeacherMapper;
import com.ywb.service.EduTeacherService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 * 讲师 服务实现类
 * </p>
 *
 * @author ywb
 * @since 2021-05-27
 */
@Service
public class EduTeacherServiceImpl extends ServiceImpl<EduTeacherMapper, EduTeacher> implements EduTeacherService {

    @Override
    public Page<EduTeacher> getByTeacherCondition(TeacherConditionVo teacherCondition, long current, long limit) {
        //获取condition中的所有值
        String teacherName = teacherCondition.getTeacherName();
        Integer teacherLevel = teacherCondition.getTeacherLevel();
        String teacherIntro = teacherCondition.getTeacherIntro();
        //创建MbpWrapper查询类
        QueryWrapper<EduTeacher> wrapper = new QueryWrapper<>();
//        当存在name的时候
        if(StringUtils.hasLength(teacherName)){
//            使用like模糊查询
            wrapper.like("name", teacherName);
        }
        if(!StringUtils.isEmpty(teacherLevel)){
            wrapper.eq("level", teacherLevel);
        }
        if(StringUtils.hasLength(teacherIntro)){
            wrapper.like("intro", teacherIntro).or().like("career", teacherIntro);
        }
        wrapper.orderByDesc("gmt_modified");

        Page<EduTeacher> pageTeacher = new Page<>(current, limit);
        page(pageTeacher, wrapper);

        return pageTeacher;

    }
}
